USE [MTNOH_SH_APP]
GO

/****** Object:  UserDefinedFunction [dbo].[FUNC_GetDictionaryIDStr]    Script Date: 09/26/2012 10:15:18 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FUNC_GetDictionaryIDStr]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[FUNC_GetDictionaryIDStr]
GO

USE [MTNOH_SH_APP]
GO

/****** Object:  UserDefinedFunction [dbo].[FUNC_GetDictionaryIDStr]    Script Date: 09/26/2012 10:15:18 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

create FUNCTION [dbo].[FUNC_GetDictionaryIDStr]
(
        @NameStr varchar(1000)
        ,@type varchar(50)
        ,@splitChar char
        ,@joinChar char
)
RETURNS VARCHAR(500)
AS
BEGIN
    DECLARE @CODE VARCHAR(1000) 
	set @CODE=''
	SELECT @CODE=@CODE + Convert(varchar(64),b.ID) + @joinChar 
	from dbo.T_Dictionary b 
	where b.Name in (select * from dbo.FUNC_ChangeStr(@NameStr,@splitChar))
	and b.ParentName=@type
	if @CODE <> ''
	  set @CODE = substring(@CODE,1,LEN(@CODE)-1)

	return @CODE
END
GO


